Skip to content

Enhance param parse for 3L and LRB#204

Merged
1a1a11a merged 1 commit into1a1a11a:developfrom
haochengxia:develop
Jun 19, 2025
Merged

Enhance param parse for 3L and LRB#204
1a1a11a merged 1 commit into1a1a11a:developfrom
haochengxia:develop

Conversation

@haochengxia
Copy link
Copy Markdown
Collaborator

Provide default values initially, then overwrite them if parameters are supplied by the user. This prevents crashes from "misuse" such as passing empty strings, which would leave objects uninitialized in the current codebase.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
E Reliability Rating on New Code (required ≥ A)
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@1a1a11a 1a1a11a requested a review from Copilot June 19, 2025 21:35
@1a1a11a 1a1a11a merged commit c144eb7 into 1a1a11a:develop Jun 19, 2025
5 of 7 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances parameter parsing in the LRB and 3LCache eviction modules by always applying default parameter values first and then overwriting them with user‐supplied values to avoid uninitialized objects. Key changes include:

  • Applying default parameters in both LRB and 3LCache interfaces before user-specific parameters are parsed.
  • Removing redundant default parsing in the else branch.
  • Adding explicit freeing of the "objective" field in both the free functions and parse functions to prevent memory leaks.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
libCacheSim/cache/eviction/LRB/LRB_Interface.cpp Default parameters applied at init, with added freeing of "objective" in both the free and parse functions.
libCacheSim/cache/eviction/3LCache/ThreeLCache_Interface.cpp Default parameters applied at init, and freeing of "objective" added in appropriate functions to ensure memory safety.
Comments suppressed due to low confidence (2)

libCacheSim/cache/eviction/LRB/LRB_Interface.cpp:98

  • Applying default parameters before parsing cache-specific parameters aligns with the PR’s objective; ensure these defaults are correctly overwritten if user parameters are provided.
  LRB_parse_params(cache, DEFAULT_PARAMS);

libCacheSim/cache/eviction/3LCache/ThreeLCache_Interface.cpp:95

  • Applying default parameters at the start ensures that all necessary fields are initialized; double-check that any cache-specific values subsequently provided correctly overwrite these defaults.
  ThreeLCache_parse_params(cache, DEFAULT_PARAMS);


if (strcasecmp(key, "objective") == 0) {
if (params->objective != NULL) {
free(params->objective);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeing the existing 'objective' before reassigning it avoids memory leaks; this practice is consistent with robust memory management.

Suggested change
free(params->objective);
free(params->objective);
params->objective = NULL;

Copilot uses AI. Check for mistakes.
@@ -133,6 +132,9 @@ static void LRB_free(cache_t *cache) {
auto *LRB = static_cast<lrb::LRBCache *>(params->LRB_cache);
delete LRB;
free(cache->to_evict_candidate);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including an explicit check and free for 'objective' in the free function helps prevent memory leaks; verify that the allocation lifecycle for 'objective' is consistently managed across code paths.

Suggested change
free(cache->to_evict_candidate);
free(cache->to_evict_candidate);
// Ensure that 'objective' is freed to prevent memory leaks.

Copilot uses AI. Check for mistakes.
}

if (strcasecmp(key, "objective") == 0) {
if (params->objective != NULL) {
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly freeing the existing 'objective' before assigning a new value prevents memory leaks; this update maintains consistency with similar patterns in the LRB module.

Copilot uses AI. Check for mistakes.
static_cast<ThreeLCache::ThreeLCacheCache *>(params->ThreeLCache_cache);
delete ThreeLCache;
free(cache->to_evict_candidate);
if (params->objective != NULL) {
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a check and free for 'objective' in the free function reinforces memory safety; ensure this pattern is uniformly applied across all similar modules.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants